package personal.xjl.studentdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import personal.xjl.studentdemo.entity.Course;
import personal.xjl.studentdemo.entity.Student;
import personal.xjl.studentdemo.service.CourseService;

import java.util.List;

@Controller
@RequestMapping("Course")
public class CourseController {
    @Autowired
    CourseService courseService;
    @RequestMapping("list.do")
    public String list(Model model, @RequestParam(value = "currPage",defaultValue = "1") int currPage, @RequestParam(value = "pageSize",defaultValue = "3") int pageSize) {
        List<Course> courses=courseService.selectByPage((currPage-1)<0?0:(currPage-1)*pageSize,pageSize);
        System.out.println(courses);
        //使用model对象将studentList的值以studentList名称带到listStudents.html页面
        model.addAttribute("courses",courses);
        model.addAttribute("currPage",currPage);
        return "listCourses";
    }
}
